<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$subject_id = mysql_real_escape_string(strip_tags($_POST['sid']));
$building_id = mysql_real_escape_string(strip_tags($_POST['building']));

$get_sname = "SELECT * FROM course_subjects WHERE id='$subject_id'";
$result_sname = mysql_query($get_sname);
$subject_name = mysql_result($result_sname,0,"subject_title");

$get_bname = "SELECT * FROM buildings WHERE id='$building_id'";
$result_bname = mysql_query($get_bname);
$building_name = mysql_result($result_bname,0,"building_name");

echo "<h1>Add Subject/Building Mapping for $subject_name</h1>";

$query = "SELECT * FROM building_subject_mapping WHERE course_subject_id = '$subject_id'";
$result = mysql_query($query);
$priority = mysql_numrows($result);
$priority++; 

$query2 = "INSERT INTO building_subject_mapping (id, course_subject_id, building_id, priority)
VALUES
('','$subject_id','$building_id','$priority')";

$result2 = mysql_query($query2);

if ($result2)
{
	echo "<b>$building_name</b> has been successfully added as a mapping for <b>$subject_name</b>!";
	echo "<br />";
}
else
{
	echo "<b>$building_name</b> was NOT able to be successfully added as a mapping for <b>$subject_name</b>!";
	echo "<br />";
}

//close
mysql_close();

echo "<p>";
	echo "<a href='index.php?id=$subject_id'>&lt;&lt; Back to Subject/Building Mapping Portal</a><br />";
echo "</p>";
?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>